﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OrzRefectorMenu.AssignUserControl;
using OrzRefectorMenu.Data;

namespace OrzRefectorMenu
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();
            if (null == AssigUCSetting.List <AssigUCSetting>().FirstOrDefault())
            {
                var setting = new AssigUCSetting();
                setting.TypeName = typeof (Assign).Name;
                setting.Height = 200;
                setting.Width = 300;
                setting.Save();
            }
            if (null == MainWindowSetting.List<MainWindowSetting>().FirstOrDefault())
            {
                var setting = new MainWindowSetting();
                setting.ContextSelectedIndex = 0;
                setting.Save();
            }
            contextComboBox.SelectedIndex = MainWindowSetting.List <MainWindowSetting>().FirstOrDefault().ContextSelectedIndex;

        }


        private void Window_Deactivated(object sender, EventArgs e)
        {
            EndAction();

        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            EndAction();
        }

        private void EndAction()
        {
            try
            {
                Close();
            }
            catch {/*ignored*/ }

        }


        private void contextComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            var s = AssigUCSetting.List < AssigUCSetting>().FirstOrDefault();

            this.Width = s.Width;
            this.Height = s.Height;

            var x = MainWindowSetting.List<MainWindowSetting>().FirstOrDefault();
            x.ContextSelectedIndex = contextComboBox.SelectedIndex;

            x.Save();
        }
    }
}
